var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/businessComponent/work-flow/NGSignatureImage.tsx
var NGSignatureImage_exports = {};
__export(NGSignatureImage_exports, {
  WfSignatureImage: () => WfSignatureImage
});
module.exports = __toCommonJS(NGSignatureImage_exports);
var import_antd = require("antd");
var import_react = require("react");
var import_baseComponent = require("../../baseComponent");
var import_functionalComponent = require("../../functionalComponent");
var import_util = require("../../util");
var import_service = require("./service");
var import_util2 = require("./util");
function WfSignatureImage(props) {
  var _a, _b;
  const [signature, setSignature] = (0, import_react.useState)({
    code: ((_a = props.signature) == null ? void 0 : _a.code) || "",
    url: ((_b = props.signature) == null ? void 0 : _b.url) || import_util.iup.getHttpUrl("NG3Resource/pic/OtherHelp_Sign.jpg")
  });
  const onChangeHandler = (0, import_util.useRefCallback)((obj) => {
    var _a2;
    setSignature(obj);
    (_a2 = props.onChange) == null ? void 0 : _a2.call(props, obj);
  });
  const handleDBClick = (0, import_util.useRefCallback)(async () => {
    const sigList = await (0, import_functionalComponent.usingProgress)(() => (0, import_service.getSignatureListByCurrentUser)(), { title: import_util2.NGLang.getSignature });
    if (!sigList.length) {
      await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.hasNoSignature);
      return;
    }
    await (0, import_util2.wfModal)({
      title: import_util2.NGLang.signatureWinTitle,
      width: 500,
      content: /* @__PURE__ */ React.createElement(ModalContent, { sigList, onChange: onChangeHandler })
    });
  });
  return /* @__PURE__ */ React.createElement(
    "div",
    {
      title: "双击选择",
      onDoubleClick: handleDBClick,
      style: {
        ...import_util2.commonStyle.borderStyle,
        cursor: "pointer",
        backgroundImage: `url(${signature.url})`,
        backgroundSize: "contain",
        backgroundPosition: "center",
        backgroundRepeat: "no-repeat",
        width: "100%",
        height: "100%",
        ...props == null ? void 0 : props.style
      }
    }
  );
}
var style = {
  main: {
    display: "flex",
    flexDirection: "column",
    padding: "5px 12px",
    height: 240
  },
  form: {
    width: "100%",
    flexWrap: "nowrap",
    marginBottom: "5px",
    justifyContent: "space-between",
    alignItems: "center"
  },
  formItem: { width: "40%" },
  btnItem: { width: "20%" },
  imgStyle: { overflow: "auto", display: "flex", flex: 1, ...import_util2.commonStyle.borderStyle }
};
function ModalContent({ sigList, onChange }) {
  const [currData, setCurrData] = (0, import_react.useState)(null);
  const [form] = import_antd.Form.useForm();
  const [btnDisabled, setBtnDisabled] = (0, import_react.useState)(true);
  const [btnLoading, setBtnLoading] = (0, import_react.useState)(false);
  const [imgSrc, setImgSrc] = (0, import_react.useState)("");
  const [pwdIsRight, setPwdIsRight] = (0, import_react.useState)(false);
  const ctx = (0, import_react.useContext)(import_functionalComponent.ModalContext);
  const previewHandler = (0, import_util.useRefCallback)(async () => {
    if (!currData || !currData.PhId) {
      await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.choseSignature);
      return;
    }
    const pwd = form.getFieldValue("pwd");
    if (!pwd) {
      await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.noPwd);
      return;
    }
    setBtnLoading(true);
    const valid = await (0, import_service.validSignatureInfoByPassword)({ PhId: currData.PhId, pwd });
    setBtnLoading(false);
    if (valid) {
      setImgSrc(currData == null ? void 0 : currData.MarkPath);
      setBtnDisabled(true);
      setPwdIsRight(true);
      return;
    }
    await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.pwdError);
  });
  const invokeOkHandler = (0, import_util.useRefCallback)(async () => {
    if (!currData) {
      await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.choseSignature);
      return;
    }
    if (!pwdIsRight) {
      const pwd = form.getFieldValue("pwd");
      if (!pwd) {
        await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.noPwd);
        return;
      } else {
        const valid = await (0, import_service.validSignatureInfoByPassword)({ PhId: currData.PhId, pwd });
        if (!valid) {
          await (0, import_util2.wfAlert)(import_util2.NGLang.alertTitle, import_util2.NGLang.pwdError);
          return;
        }
      }
    }
    onChange == null ? void 0 : onChange({ code: currData.PhId, url: currData.MarkPath });
    ctx.ins.destroy();
  });
  (0, import_react.useEffect)(() => {
    ctx.ins.setApi({
      invokeOkHandler,
      invokeCancelHandler: () => {
        ctx.ins.destroy();
      }
    });
  }, [invokeOkHandler]);
  const handleSignatureSelect = (0, import_util.useRefCallback)((val, { origin }) => {
    form.setFieldsValue({ pwd: "" });
    if (origin.MarkPass) {
      setPwdIsRight(false);
      setImgSrc("");
      setBtnDisabled(false);
    } else {
      setPwdIsRight(true);
      setImgSrc(origin.MarkPath);
      setBtnDisabled(true);
    }
    setCurrData(origin);
  });
  return /* @__PURE__ */ React.createElement("main", { style: style.main }, /* @__PURE__ */ React.createElement(import_antd.Form, { layout: "inline", style: style.form, form }, /* @__PURE__ */ React.createElement(
    import_antd.Form.Item,
    {
      style: style.formItem,
      messageVariables: { another: "good" },
      label: import_util2.NGLang.taskHisSignature,
      name: "cname"
    },
    /* @__PURE__ */ React.createElement(
      import_baseComponent.Select,
      {
        size: "small",
        placeholder: import_util2.NGLang.signatureWinTitle,
        options: sigList,
        onSelect: handleSignatureSelect
      }
    )
  ), /* @__PURE__ */ React.createElement(import_antd.Form.Item, { style: style.formItem, label: import_util2.NGLang.pwd, name: "pwd" }, /* @__PURE__ */ React.createElement(import_baseComponent.Password, { size: "small" })), /* @__PURE__ */ React.createElement(import_functionalComponent.Button, { size: "small", loading: btnLoading, type: "primary", onClick: previewHandler, disabled: btnDisabled }, import_util2.NGLang.perview)), /* @__PURE__ */ React.createElement("div", { style: style.imgStyle }, /* @__PURE__ */ React.createElement("img", { src: imgSrc, style: { margin: "auto" }, alt: "" })));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  WfSignatureImage
});
